package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.emuns.Operator;
	import com.terrynoya.fight.emuns.StateTypeEnum;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;
	import com.terrynoya.fight.util.Misc;

	public class P2StateType
	{
		public function P2StateType()
		{
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var chara:Character = data as Character;
			if(chara == null)
			{
				return false;
			}
			var oper:int = node.arguments[0];
			var stateType:int = node.arguments[1];
			
			var opponent:Character = chara.getOpponent();
			if(opponent == null)
			{
				return false;
			}
			
			switch(oper)
			{
				case Operator.Equals:
				{
					return stateType == opponent.state;
					break;
				}
				case Operator.NotEquals:
				{
					return stateType != opponent.state;
					break;
				}
			}
		}
		
		public static function parse(state:ParseState):Node
		{
			var oper:int = state.currentOperator;
			if(oper != Operator.Equals && oper != Operator.NotEquals)
			{
				return null;
			}
			state.tokenIndex ++;
			
			var stateType:int = Misc.getStateType(state.currentToken.text);
			if(stateType == StateTypeEnum.Unchanged || stateType == StateTypeEnum.NONE)
			{
				return null;
			}
			
			state.tokenIndex ++;
			state.baseNode.arguments.push(oper);
			state.baseNode.arguments.push(stateType);
			return state.baseNode;
		}
	}
}